package com.easy.frame.common.mq.rabbit.config;

import com.easy.frame.common.mq.rabbit.RabbitConstants;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Exchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 被拒绝的消息会进入死信队列
 *
 * @author 86131
 */
@Configuration
public class RabbitDeadLetterConfiguration {
    /**
     * 死信队列
     */
    @Bean(name = "deadQueueLetter")
    public Queue deadLetterQueue() {
        return new Queue(RabbitConstants.Queue.EF_DEADLETTER_QUEUE, true, false, false, null);
    }

    @Bean(name = "deadLetterExchage")
    public Exchange deleteLetterExchange() {
        return new DirectExchange(RabbitConstants.Exchange.EF_DEADLETTER_EXCHANGE, true, false);
    }

    @Bean(name = "deadLetterBinding")
    public Binding deadLetterBinding() {
        return new Binding(RabbitConstants.Queue.EF_DEADLETTER_QUEUE, Binding.DestinationType.QUEUE,
                RabbitConstants.Exchange.EF_DEADLETTER_EXCHANGE, RabbitConstants.Key.EF_DEADLETTER_KEY, null);
    }
}
